package goldberg.drew.twitter;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;


public class ConcurrentTwitter extends AbstractTwitter {
	final static int numberOfCores = Runtime.getRuntime().availableProcessors();
	final static double blockingCoefficient = 0.9;
	final static ExecutorService executorPool = Executors.newFixedThreadPool(calculateNumberOfThreads(numberOfCores, blockingCoefficient));
	final List<Callable<UserTweets>> userPartition = new ArrayList<Callable<UserTweets>>();	

	private void init() {
		ConcurrentTwitter.createUsers();
	}

	public static ConcurrentTwitter create() {
		ConcurrentTwitter concurrentTwitter = new ConcurrentTwitter();
		concurrentTwitter.init();
		return concurrentTwitter;
	
	}

	public static int calculateNumberOfThreads (final int numberOfCores, final double blockingCoefficient) {
		System.out.println("The number of threads is " + (int)((numberOfCores)/(1.0 - blockingCoefficient)));		
		return (int)((numberOfCores)/(1.0 - blockingCoefficient));
	}

	public void createAllTasks() {
		for(String user: users.keySet()) {
			for(int i = 1; i < 17; i++) {
				final int pageNumber = i;
				userPartition.add(new Callable<UserTweets>() {
					public UserTweets call() {

					}				
				}
				
			}
			
		}	
	
	}

	





}
